using System;
using System.Collections.Generic;
using System.Text;
//using Xfinity.Console;
using System.IO;
using System.Diagnostics;
using Xfinity.Console;

namespace Xfinity.Scripting.Xscript
{
    [Serializable]
    public class ScriptExecutionException : Exception
    {
        public ScriptExecutionException()
        {

        }
        public ScriptExecutionException(Exception e)
            : base("", e)
        {

        }
    }
    public class CommandScript
    {
        private List<string> script;

        /// <summary>
        /// The commands.
        /// </summary>
        public List<string> Script
        {
            get { return script; }
            set { script = value; }
        }
        public CommandScript()
        {
            script = new List<string>();
        }
        public CommandScript(string script)
        {
            ParseScript(script);
        }

        [DebuggerStepThrough]
        private void ParseScript(string script)
        {
            string[] commands = script.Split(';');
            this.script = new List<string>(commands);
        }
        public CommandScript(TextReader input)
        {
            ParseScript(input.ReadToEnd());
        }
        public CommandScript(IEnumerable<string> existing)
        {
            script = new List<string>(existing);
        }
        public CommandScript(int numberOfCommands)
        {
            script = new List<string>(numberOfCommands);
        }

        public void Execute()
        {
            try
            {
                foreach (string command in script)
                {
                    CommandParser.ProcessCommand(command);
                }
            }
            catch (Exception e)
            {
                throw new ScriptExecutionException(e);
            }
        }
    }
}